package com.lanyun.serviceimpl;


import com.lanyun.dao.EmpDao;
import com.lanyun.pojo.Dept;
import com.lanyun.pojo.Emp;
import com.lanyun.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class EmpServiceImpl implements EmpService {
    @Autowired
    private EmpDao empDao;
    @Override
    public List<Emp> getAll() {
        return empDao.getAll();
    }

    @Override
    public List<Emp> findEmpById(Integer id) {
        return empDao.findAllEmpById(id);
    }


    @Override
    public Integer insertEmp(Emp emp) {
        return empDao.createEmp(emp);
    }

    @Override
    public Integer deleteEmp(Integer id) {
        return empDao.deleteEmpById(id);
    }

    @Override
    public Integer deleteSomeEmp(String ids) {//批量删除--拿到选中的CheckBox--id进行批量删除
        String id = ids.substring(0,ids.length()-1);
        String [] array = id.split(",");
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < array.length; i++) {
            list.add(Integer.parseInt(array[i]));
        }
        return empDao.deleteSomeById(list);
    }

    @Override
    public Emp findEmp_update(Integer id) {
        return empDao.find_update(id);
    }

    @Override
    public Integer updateEmp(Emp emp) {
        return empDao.empUpdate(emp);
    }
}